<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>欢迎页面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: background 0.5s ease;
        }

        .container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            padding: 40px;
            text-align: center;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            max-width: 500px;
            width: 90%;
            animation: slideIn 0.8s ease-out;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .welcome-content {
            color: #333;
        }

        .welcome-title {
            font-size: 3rem;
            margin-bottom: 20px;
            background: linear-gradient(45deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            animation: titleGlow 2s ease-in-out infinite alternate;
        }

        @keyframes titleGlow {
            from {
                text-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
            }
            to {
                text-shadow: 0 0 30px rgba(118, 75, 162, 0.8);
            }
        }

        .welcome-message {
            font-size: 1.2rem;
            margin-bottom: 30px;
            color: #666;
            line-height: 1.6;
        }

        .welcome-buttons {
            display: flex;
            gap: 20px;
            justify-content: center;
            flex-wrap: wrap;
        }

        .btn {
            padding: 12px 30px;
            border: none;
            border-radius: 50px;
            font-size: 1rem;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .btn-primary {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
        }

        .btn-secondary {
            background: linear-gradient(45deg, #f093fb, #f5576c);
            color: white;
            box-shadow: 0 4px 15px rgba(240, 147, 251, 0.4);
        }

        .btn-secondary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(240, 147, 251, 0.6);
        }

        .btn:active {
            transform: translateY(0);
        }

        /* 用户信息卡片样式 */
        .user-info-card {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            padding: 25px;
            margin: 30px 0;
            display: flex;
            align-items: center;
            gap: 20px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            animation: slideInUp 0.6s ease-out;
        }

        @keyframes slideInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .user-avatar {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            overflow: hidden;
            border: 3px solid rgba(255, 255, 255, 0.3);
            flex-shrink: 0;
        }

        .user-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .user-details {
            flex: 1;
            text-align: left;
        }

        .user-details h3 {
            margin: 0 0 8px 0;
            color: #333;
            font-size: 1.3rem;
            font-weight: bold;
        }

        .user-details p {
            margin: 4px 0;
            color: #666;
            font-size: 0.95rem;
        }

        .user-details p:last-child {
            font-family: 'Courier New', monospace;
            background: rgba(0, 0, 0, 0.05);
            padding: 4px 8px;
            border-radius: 5px;
            display: inline-block;
        }

        /* 加载状态样式 */
        .loading-container {
            text-align: center;
            margin: 40px 0;
        }

        .loading-spinner {
            width: 50px;
            height: 50px;
            border: 4px solid rgba(102, 126, 234, 0.2);
            border-top: 4px solid #667eea;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .loading-container p {
            color: #666;
            font-size: 1rem;
        }

        /* 错误状态样式 */
        .error-container {
            text-align: center;
            margin: 40px 0;
            padding: 30px;
            background: rgba(255, 0, 0, 0.05);
            border-radius: 15px;
            border: 1px solid rgba(255, 0, 0, 0.1);
        }

        .error-icon {
            font-size: 3rem;
            margin-bottom: 15px;
        }

        .error-container p {
            color: #e74c3c;
            margin-bottom: 20px;
            font-size: 1rem;
        }

        /* 深色主题 */
        body.dark-theme {
            background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
        }

        body.dark-theme .container {
            background: rgba(44, 62, 80, 0.95);
            color: #ecf0f1;
        }

        body.dark-theme .welcome-title {
            background: linear-gradient(45deg, #3498db, #9b59b6);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        body.dark-theme .welcome-message {
            color: #bdc3c7;
        }

        body.dark-theme .user-info-card {
            background: rgba(44, 62, 80, 0.3);
            border-color: rgba(255, 255, 255, 0.1);
        }

        body.dark-theme .user-details h3 {
            color: #ecf0f1;
        }

        body.dark-theme .user-details p {
            color: #bdc3c7;
        }

        body.dark-theme .user-details p:last-child {
            background: rgba(255, 255, 255, 0.1);
            color: #ecf0f1;
        }

        body.dark-theme .loading-container p {
            color: #bdc3c7;
        }

        body.dark-theme .error-container {
            background: rgba(231, 76, 60, 0.1);
            border-color: rgba(231, 76, 60, 0.2);
        }

        body.dark-theme .error-container p {
            color: #e74c3c;
        }

        /* 移动端优化 */
        @media (max-width: 600px) {
            body {
                padding: 0;
                margin: 0;
                min-height: 100vh;
            }
            
            .container {
                padding: 20px 15px;
                margin: 10px;
                border-radius: 15px;
                min-height: calc(100vh - 20px);
                display: flex;
                flex-direction: column;
                justify-content: center;
            }
            
            .welcome-title {
                font-size: 2.2rem;
                margin-bottom: 15px;
            }
            
            .welcome-message {
                font-size: 1rem;
                margin-bottom: 25px;
                line-height: 1.5;
            }
            
            .user-info-card {
                flex-direction: column;
                text-align: center;
                padding: 20px 15px;
                margin: 20px 0;
                border-radius: 12px;
            }
            
            .user-avatar {
                width: 80px;
                height: 80px;
                margin: 0 auto 15px;
            }
            
            .user-details {
                text-align: center;
            }
            
            .user-details h3 {
                font-size: 1.1rem;
                margin-bottom: 8px;
            }
            
            .user-details p {
                font-size: 0.9rem;
                margin: 6px 0;
            }
            
            .welcome-buttons {
                flex-direction: column;
                align-items: center;
                margin-top: 20px;
            }
            
            .btn {
                width: 100%;
                max-width: 250px;
                margin: 8px 0;
                padding: 14px 20px;
                font-size: 1rem;
            }
            
            .loading-container {
                margin: 30px 0;
            }
            
            .loading-spinner {
                width: 40px;
                height: 40px;
            }
            
            .error-container {
                margin: 20px 0;
                padding: 20px 15px;
            }
            
            .error-container p {
                font-size: 0.9rem;
                line-height: 1.4;
            }
        }

        /* 超小屏幕优化 */
        @media (max-width: 400px) {
            .container {
                padding: 15px 10px;
                margin: 5px;
            }
            
            .welcome-title {
                font-size: 1.8rem;
            }
            
            .welcome-message {
                font-size: 0.95rem;
            }
            
            .user-info-card {
                padding: 15px 10px;
            }
            
            .user-avatar {
                width: 70px;
                height: 70px;
            }
        }

        /* Telegram WebApp 特殊优化 */
        @media (max-width: 600px) and (orientation: portrait) {
            .container {
                min-height: 100vh;
                margin: 0;
                border-radius: 0;
            }
        }

        /* 移动端设备特殊样式 */
        .mobile-device .container {
            border-radius: 0;
            margin: 0;
            min-height: 100vh;
        }

        .mobile-device .btn {
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
        }

        .mobile-device .user-info-card {
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }

        /* 防止移动端滚动问题 */
        .mobile-device {
            overflow-x: hidden;
        }

        .mobile-device .container {
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="welcome-content">
            <h1 class="welcome-title">幸运转盘</h1>
            <p class="welcome-message">欢迎来到幸运转盘！正在获取您的Telegram信息...</p>
            
            <!-- 用户信息卡片 -->
            <div class="user-info-card" id="userInfoCard" style="display: none;">
                <div class="user-avatar">
                    <img id="userAvatar" src="" alt="用户头像">
                </div>
                <div class="user-details">
                    <h3 id="userName">用户名</h3>
                    <p id="userNickname">昵称</p>
                    <p id="userId">ID: <span id="userIdValue">-</span></p>
                </div>
            </div>
            
            <!-- 加载状态 -->
            <div class="loading-container" id="loadingContainer">
                <div class="loading-spinner"></div>
                <p>正在获取用户信息...</p>
            </div>
            
            <!-- 错误状态 -->
            <div class="error-container" id="errorContainer" style="display: none;">
                <div class="error-icon">⚠️</div>
                <p>无法获取用户信息，请通过Telegram打开此链接</p>
                <button class="btn btn-primary" onclick="retryGetUserInfo()">重试</button>
            </div>
            
            <div class="welcome-buttons">
                <button class="btn btn-primary" id="startButton" onclick="startWheel()" style="display: none;">开始转盘</button>
                <button class="btn btn-secondary" onclick="changeTheme()">切换主题</button>
                <button class="btn btn-secondary" onclick="showDebugInfo()" style="background: #f39c12; margin-top: 10px;">调试信息</button>
            </div>
        </div>
    </div>
    
    <script src="https://telegram.org/js/telegram-web-app.js"></script>
    <script>
        // Telegram WebApp API
        let tg = null;
        let userInfo = null;

        // 初始化Telegram WebApp
        function initTelegramWebApp() {
            console.log('开始初始化Telegram WebApp...');
            console.log('window.Telegram存在:', !!window.Telegram);
            console.log('window.Telegram.WebApp存在:', !!(window.Telegram && window.Telegram.WebApp));
            
            // 检查是否在Telegram环境中
            if (window.Telegram && window.Telegram.WebApp) {
                tg = window.Telegram.WebApp;
                console.log('Telegram WebApp对象:', tg);
                
                tg.ready();
                tg.expand();
                
                // 检查initDataUnsafe
                console.log('tg.initDataUnsafe:', tg.initDataUnsafe);
                console.log('tg.initDataUnsafe.user:', tg.initDataUnsafe?.user);
                
                // 检查initData
                console.log('tg.initData:', tg.initData);
                
                // 获取用户信息
                userInfo = tg.initDataUnsafe?.user;
                
                if (userInfo) {
                    console.log('通过initDataUnsafe获取到用户信息:', userInfo);
                    displayUserInfo(userInfo);
                } else {
                    // 尝试从initData中解析用户信息
                    console.log('尝试从initData解析用户信息...');
                    parseInitData();
                }
            } else {
                console.log('不在Telegram环境中，尝试从URL参数获取');
                // 尝试从URL参数获取（作为备用方案）
                getUserInfoFromURL();
            }
        }

        // 解析Telegram initData
        function parseInitData() {
            console.log('开始解析initData...');
            
            if (tg && tg.initData && tg.initData.trim() !== '') {
                console.log('initData内容:', tg.initData);
                
                try {
                    const initData = new URLSearchParams(tg.initData);
                    console.log('解析后的initData参数:', Object.fromEntries(initData));
                    
                    const userParam = initData.get('user');
                    console.log('user参数:', userParam);
                    
                    if (userParam) {
                        const userData = JSON.parse(decodeURIComponent(userParam));
                        console.log('解析的用户信息:', userData);
                        displayUserInfo(userData);
                        return;
                    }
                } catch (e) {
                    console.error('解析initData失败:', e);
                }
            } else {
                console.log('tg或tg.initData不存在或为空');
                
                // 尝试其他方法获取用户信息
                tryAlternativeMethods();
                return;
            }
            
            // 如果无法获取用户信息，显示错误
            console.log('无法获取用户信息，显示错误页面');
            showError();
        }

        // 尝试其他方法获取用户信息
        function tryAlternativeMethods() {
            console.log('尝试其他方法获取用户信息...');
            
            // 方法1：检查是否有其他Telegram相关对象
            if (window.TelegramWebviewProxy) {
                console.log('发现TelegramWebviewProxy');
                // 可以尝试使用TelegramWebviewProxy
            }
            
            // 方法2：检查URL中是否有用户信息
            const urlParams = new URLSearchParams(window.location.search);
            const hasUserParams = urlParams.has('username') || urlParams.has('user') || urlParams.has('id');
            
            if (hasUserParams) {
                console.log('URL中发现用户参数，尝试解析...');
                getUserInfoFromURL();
                return;
            }
            
            // 方法3：显示特殊提示
            showTelegramSpecificError();
        }

        // 显示Telegram特定错误
        function showTelegramSpecificError() {
            const loadingContainer = document.getElementById('loadingContainer');
            const errorContainer = document.getElementById('errorContainer');
            
            loadingContainer.style.display = 'none';
            
            errorContainer.innerHTML = `
                <div class="error-icon">📱</div>
                <h3>Telegram WebApp 初始化问题</h3>
                <p>检测到您在Telegram中，但无法获取用户信息</p>
                <div style="text-align: left; margin: 20px 0; padding: 15px; background: rgba(0,0,0,0.05); border-radius: 10px;">
                    <p><strong>可能的原因：</strong></p>
                    <p>1. 直接点击链接（非WebApp按钮）</p>
                    <p>2. Telegram版本不支持WebApp</p>
                    <p>3. 需要Bot发送WebApp按钮</p>
                    <br>
                    <p><strong>解决方案：</strong></p>
                    <p>请通过Telegram Bot发送WebApp按钮，或使用以下测试链接：</p>
                    <p style="font-size: 0.9rem; color: #666; margin-top: 10px;">
                        <code>http://38.45.123.218:36699/?username=test&nickname=测试用户&id=123456789</code>
                    </p>
                </div>
                <button class="btn btn-primary" onclick="retryGetUserInfo()">重试</button>
                <button class="btn btn-secondary" onclick="testWithParams()" style="margin-left: 10px;">使用测试参数</button>
            `;
            errorContainer.style.display = 'block';
        }

        // 使用测试参数
        function testWithParams() {
            const testUser = {
                username: 'test_user',
                first_name: '测试用户',
                last_name: '',
                id: 123456789,
                photo_url: null
            };
            
            displayUserInfo(testUser);
        }

        // 从URL参数获取用户信息
        function getUserInfoFromURL() {
            const urlParams = new URLSearchParams(window.location.search);
            
            // 尝试获取各种可能的参数
            const username = urlParams.get('username') || urlParams.get('user') || urlParams.get('tg');
            const nickname = urlParams.get('nickname') || urlParams.get('name') || urlParams.get('first_name');
            const userId = urlParams.get('id') || urlParams.get('uid') || urlParams.get('user_id');
            const avatar = urlParams.get('avatar') || urlParams.get('photo') || urlParams.get('photo_url');
            
            if (username || userId) {
                const mockUserInfo = {
                    username: username ? username.replace('@', '') : null,
                    first_name: nickname || '用户',
                    last_name: urlParams.get('last_name') || '',
                    id: userId ? parseInt(userId) : null,
                    photo_url: avatar || null
                };
                
                displayUserInfo(mockUserInfo);
            } else {
                showError();
            }
        }

        // 显示用户信息
        function displayUserInfo(user) {
            console.log('显示用户信息:', user);
            
            const userInfoCard = document.getElementById('userInfoCard');
            const loadingContainer = document.getElementById('loadingContainer');
            const startButton = document.getElementById('startButton');
            
            // 隐藏加载状态
            loadingContainer.style.display = 'none';
            
            // 填充用户信息
            if (user.photo_url) {
                document.getElementById('userAvatar').src = user.photo_url;
                console.log('设置用户头像:', user.photo_url);
            } else {
                // 使用默认头像
                document.getElementById('userAvatar').src = 'data:image/svg+xml;base64,' + btoa(`
                    <svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <circle cx="40" cy="40" r="40" fill="#667eea"/>
                        <circle cx="40" cy="30" r="12" fill="white"/>
                        <path d="M20 65c0-11 9-20 20-20s20 9 20 20" fill="white"/>
                    </svg>
                `);
                console.log('使用默认头像');
            }
            
            // 显示用户名（如果有的话）
            const username = user.username ? `@${user.username}` : '未设置用户名';
            document.getElementById('userName').textContent = username;
            console.log('用户名:', username);
            
            // 显示昵称
            const fullName = `${user.first_name || ''} ${user.last_name || ''}`.trim();
            document.getElementById('userNickname').textContent = fullName || '未知昵称';
            console.log('昵称:', fullName);
            
            // 显示用户ID
            document.getElementById('userIdValue').textContent = user.id || '未知';
            console.log('用户ID:', user.id);
            
            // 显示用户信息卡片和开始按钮
            userInfoCard.style.display = 'block';
            startButton.style.display = 'inline-block';
            
            // 更新欢迎消息
            const displayName = user.first_name || user.username || '用户';
            document.querySelector('.welcome-message').textContent = `欢迎 ${displayName}！准备开始幸运转盘吧！`;
            console.log('欢迎消息已更新:', displayName);
            
            // 保存用户信息到全局变量
            userInfo = user;
            
            // 显示成功通知
            showSuccessNotification(user);
        }

        // 显示成功通知
        function showSuccessNotification(user) {
            const notification = document.createElement('div');
            notification.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                background: linear-gradient(45deg, #4CAF50, #45a049);
                color: white;
                padding: 12px 20px;
                border-radius: 10px;
                box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
                z-index: 1000;
                font-size: 14px;
                animation: slideInRight 0.5s ease-out;
            `;
            notification.textContent = `✅ 成功获取用户信息！`;
            
            document.body.appendChild(notification);
            
            // 3秒后自动移除通知
            setTimeout(() => {
                notification.style.animation = 'slideInRight 0.5s ease-out reverse';
                setTimeout(() => {
                    if (notification.parentNode) {
                        notification.parentNode.removeChild(notification);
                    }
                }, 500);
            }, 3000);
        }

        // 显示错误状态
        function showError() {
            const loadingContainer = document.getElementById('loadingContainer');
            const errorContainer = document.getElementById('errorContainer');
            
            loadingContainer.style.display = 'none';
            
            // 更新错误提示内容
            errorContainer.innerHTML = `
                <div class="error-icon">⚠️</div>
                <h3>无法获取用户信息</h3>
                <p>请确保您是通过Telegram打开此链接</p>
                <div style="text-align: left; margin: 20px 0; padding: 15px; background: rgba(0,0,0,0.05); border-radius: 10px;">
                    <p><strong>使用方法：</strong></p>
                    <p>1. 在Telegram中点击此链接</p>
                    <p>2. 或者通过Telegram Bot发送WebApp按钮</p>
                    <p style="font-size: 0.9rem; color: #666; margin-top: 10px;">
                        <strong>注意：</strong>只有在Telegram应用中打开才能自动获取用户信息
                    </p>
                </div>
                <button class="btn btn-primary" onclick="retryGetUserInfo()">重试</button>
            `;
            errorContainer.style.display = 'block';
        }

        // 重试获取用户信息
        function retryGetUserInfo() {
            const loadingContainer = document.getElementById('loadingContainer');
            const errorContainer = document.getElementById('errorContainer');
            
            errorContainer.style.display = 'none';
            loadingContainer.style.display = 'block';
            
            // 重新尝试获取用户信息
            setTimeout(() => {
                initTelegramWebApp();
            }, 1000);
        }

        // 开始转盘
        function startWheel() {
            if (userInfo) {
                alert(`欢迎 ${userInfo.first_name || '用户'}！转盘功能即将开始...`);
                // 这里可以添加实际的转盘逻辑
                // 例如：window.location.href = 'wheel.html?user=' + encodeURIComponent(JSON.stringify(userInfo));
            }
        }

        function changeTheme() {
            document.body.classList.toggle('dark-theme');
            
            // 保存主题偏好到本地存储
            const isDark = document.body.classList.contains('dark-theme');
            localStorage.setItem('theme', isDark ? 'dark' : 'light');
        }

        // 显示调试信息
        function showDebugInfo() {
            const debugInfo = {
                'User Agent': navigator.userAgent,
                'Telegram WebApp存在': !!(window.Telegram && window.Telegram.WebApp),
                'tg对象': tg ? '存在' : '不存在',
                'tg.initData': tg ? tg.initData : 'N/A',
                'tg.initDataUnsafe': tg ? tg.initDataUnsafe : 'N/A',
                'tg.initDataUnsafe.user': tg ? tg.initDataUnsafe?.user : 'N/A',
                '当前URL': window.location.href,
                'URL参数': Object.fromEntries(new URLSearchParams(window.location.search)),
                '是否在Telegram中': !!(window.Telegram && window.Telegram.WebApp),
                'initData长度': tg ? tg.initData.length : 0,
                '用户信息': userInfo || '未获取到'
            };
            
            let debugText = '🔍 调试信息:\n\n';
            for (const [key, value] of Object.entries(debugInfo)) {
                debugText += `${key}: ${JSON.stringify(value, null, 2)}\n\n`;
            }
            
            // 添加用户信息详情
            if (userInfo) {
                debugText += '👤 用户信息详情:\n';
                debugText += `• 用户ID: ${userInfo.id}\n`;
                debugText += `• 昵称: ${userInfo.first_name} ${userInfo.last_name || ''}\n`;
                debugText += `• 用户名: @${userInfo.username || '未设置'}\n`;
                debugText += `• 头像: ${userInfo.photo_url || '无'}\n\n`;
            }
            
            // 添加使用说明
            debugText += '📱 使用说明:\n';
            debugText += '1. 通过Telegram Bot发送WebApp按钮\n';
            debugText += '2. 点击按钮打开此页面\n';
            debugText += '3. 页面会自动获取用户信息\n';
            debugText += '4. 无需用户手动授权\n\n';
            debugText += '❌ 直接点击链接无法获取用户信息\n';
            debugText += '✅ 必须通过Bot的WebApp按钮\n';
            
            alert(debugText);
            console.log('调试信息:', debugInfo);
        }

        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 检查保存的主题
            const savedTheme = localStorage.getItem('theme');
            if (savedTheme === 'dark') {
                document.body.classList.add('dark-theme');
            }
            
            // 移动端优化
            optimizeForMobile();
            
            // 初始化Telegram WebApp
            initTelegramWebApp();
        });

        // 移动端优化函数
        function optimizeForMobile() {
            // 检测移动端
            const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
            
            if (isMobile) {
                console.log('检测到移动端设备');
                
                // 添加移动端特定的样式类
                document.body.classList.add('mobile-device');
                
                // 优化触摸体验
                document.body.style.touchAction = 'manipulation';
                
                // 防止双击缩放
                let lastTouchEnd = 0;
                document.addEventListener('touchend', function (event) {
                    const now = (new Date()).getTime();
                    if (now - lastTouchEnd <= 300) {
                        event.preventDefault();
                    }
                    lastTouchEnd = now;
                }, false);
                
                // 优化视口
                const viewport = document.querySelector('meta[name="viewport"]');
                if (viewport) {
                    viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no');
                }
            }
        }

        // 添加一些交互效果
        document.addEventListener('DOMContentLoaded', function() {
            // 为按钮添加点击动画
            const buttons = document.querySelectorAll('.btn');
            buttons.forEach(button => {
                button.addEventListener('click', function() {
                    this.style.transform = 'scale(0.95)';
                    setTimeout(() => {
                        this.style.transform = '';
                    }, 150);
                });
            });

            // 添加鼠标跟随效果
            document.addEventListener('mousemove', function(e) {
                const container = document.querySelector('.container');
                const x = e.clientX / window.innerWidth;
                const y = e.clientY / window.innerHeight;
                
                container.style.transform = `perspective(1000px) rotateY(${x * 10 - 5}deg) rotateX(${y * 10 - 5}deg)`;
            });

            // 重置容器变换
            document.addEventListener('mouseleave', function() {
                const container = document.querySelector('.container');
                container.style.transform = 'perspective(1000px) rotateY(0deg) rotateX(0deg)';
            });
        });
    </script>
</body>
</html>